<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>inheritPrototype</title>
</head>

<body>
    <div>打开浏览器控制台查看结果</div>
    <script>
        const inheritPrototype = (subType, supType) => {
            const object = o => {
                function F() { };
                F.prototype = o;
                return new F();
            };
            const pro = object(supType.prototype);
            pro.constructor = subType;
            subType.prototype = pro;
        };
        function SuperType(name) {
            this.name = name;
            this.colors = ['red', 'blue', 'green'];
        }
        SuperType.prototype.sayName = function () {
            console.log(this.name);
        };
        function SubType(name, age) {
            SuperType.call(this, name);
            this.age = age;
        }
        inheritPrototype(SubType, SuperType);
        SubType.prototype.sayAge = function () {
            console.log(this.age);
        };

        const sub1 = new SubType('eveningwater');
        sub1.sayName(); // eveningwater
    </script>
</body>

</html>